#include<bits/stdc++.h>

using namespace std;
int a,b;
string zhengshubufen(int x)
{
	string res="";
	while(x)
	{
		res+=to_string(x%3);
		x/=3;
	}
	reverse(res.begin(),res.end());
	return res;	
}
string xiaoshubufen(int x,int y)
{
	string res="";
	while(y!=1)
	{
		y/=3;
		res+=to_string(x/y);
		x=x%y;
	}
	return res;
}
deque<int> shu;
int main()
{
	//cout<<zhengshubufen(8);
	cin>>a>>b;
	int flag=false;
	if(a<0)flag=true;
	a=abs(a);
	string zhengshu=zhengshubufen(a/b);
	int c=a%b;
	string xiaoshu=xiaoshubufen(c,b);
	//cout<<zhengshu;
	//cout<<xiaoshubufen(c,b);
	string sanjinzhi=zhengshu+xiaoshu;
	for(auto p:sanjinzhi)
	{
		shu.push_back(p-'0');
	}
	//for(auto p:shu)cout<<p;
	//cout<<endl;
	deque<int> jiayi;
	bool jinwei=false;
	while(!shu.empty())
	{
		int x=shu.back()+(jinwei?2:1);
		//cout<<x<<endl;
		if(x>=3)jiayi.push_front(x%3),jinwei=true;
		else jiayi.push_front(x),jinwei=false;
		shu.pop_back();
		if(shu.empty()&&jinwei)jiayi.push_front(1);
	}
//	for(auto p:jiayi)cout<<p;
//	cout<<endl;
	vector<int> res;
	int ccnt=jiayi.size()-sanjinzhi.size();
	while(!jiayi.empty())
	{
		
		if(ccnt<=0&&(jiayi.front()-1)==-1)res.push_back(2);
		else if(ccnt<=0) res.push_back(jiayi.front()-1);
		else res.push_back(jiayi.front());
		//res.push_back((jiayi.front()-1)==-1?2:(jiayi.front()-1));
		jiayi.pop_front();
		ccnt--;
	}
	int cnt=0,sz=res.size();
	for(auto p:res)
	{
		if(sz-cnt==xiaoshu.size())cout<<".";
		if(flag&&p==1)cout<<2;
		else if(flag&&p==2)cout<<1;
		else cout<<p;
		cnt++;
	}
	return 0;
}
